//
//  SubscriptButton.m
//  TTLoveCar
//
//  Created by Gary on 06/03/2018.
//  Copyright © 2018 王洋. All rights reserved.
//

#import "SubscriptButton.h"

@interface SubscriptButton ()

@end

@implementation SubscriptButton

- (id)initWithSize:(CGSize)size {
    self =  [self init];
    self.frame = CGRectMake(0, 0, size.width, size.height);
    
    return self;
}


- (id)init {
    self = [super init];
    if (self) {
        _showMessageCount = YES;
        [self addSubview:self.topButton];
        [self addSubview:self.countLabel];
        
    }
    return self;
}

- (void)setCountNum:(NSInteger)count {
    if (!_showMessageCount) {
        return;
    }
    _messageCount = count;
    
    if (_messageCount <= 0) {
        _countLabel.text = nil;
    }else if (_messageCount < 99) {
        _countLabel.text = [NSString stringWithFormat:@"%@",@(_messageCount)];
    }else {
        _countLabel.text = @"99+";
    }
}

#pragma CreateView

- (TT_DockItem*)topButton {
    if (!_topButton) {
        _topButton = [[TT_DockItem alloc]init];
        _topButton.frame = CGRectMake(0, 0, 40, 40);
        _topButton.backgroundColor = [UIColor clearColor];
        [_topButton setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];
        _topButton.titleLabel.font = [UIFont systemFontOfSize:8];
        _topButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        _topButton.contentMode = UIViewContentModeTopRight;
        _topButton.clipsToBounds = YES;
        
    }
    return _topButton;
}



- (UILabel*)countLabel {
    if (!_countLabel) {
        _countLabel = [[UILabel alloc]init];
        _countLabel.frame = CGRectMake(30, 0, 10, 8);
        _countLabel.layer.cornerRadius = 4;
        _countLabel.layer.masksToBounds = YES;
        _countLabel.backgroundColor = [UIColor redColor];;
        _countLabel.textColor = [UIColor whiteColor];
        _countLabel.font = [UIFont systemFontOfSize:8];
        _countLabel.textAlignment = NSTextAlignmentCenter;
        _messageCount = 0;
        _countLabel.text = nil;
    }
    return  _countLabel;
}

@end
